package com.xuzhiguang.baidu.pan.sdk.token;

import java.util.HashMap;
import java.util.Map;

/**
 * @author xuzhiguang
 * @date 2020/6/25 23:34
 */
public class InMemoryTokenStorage implements ITokenStorage {

    private Map<String, AccessToken> accessTokens = new HashMap<>();

    /**
     * 保存token
     *
     * @param apiKey
     * @param accessToken
     */
    @Override
    public synchronized void save(String apiKey, AccessToken accessToken) {
        accessTokens.put(apiKey, accessToken);
    }

    /**
     * @param apiKey
     * @return
     */
    @Override
    public AccessToken get(String apiKey) {

        AccessToken accessToken = accessTokens.get(apiKey);
        return accessToken;
    }

    /**
     * 删除token
     *
     * @param apiKey
     */
    @Override
    public synchronized void delete(String apiKey) {
        accessTokens.remove(apiKey);
    }
}
